package com.ch9;

import java.util.Arrays;
import java.util.Random;

/**
 * 采用哨兵的方式求数值的最大值
 * @author Linxiaozhi
 *
 */
public class Max {
	static void fun(int[] arr) {
		int i = 0;
		int size = arr.length - 1;
		int n = size;
		while (i < size) {
			int max = arr[i];
			arr[n] = arr[i];
			i++;
			while (arr[i] < max)
				i++;
		}
		System.out.println("max:" + arr[n]);
	}

	public static void main(String[] args) {
		int size = 10;
		Random rand = new Random();
		int[] a = new int[size];
		for (int i = 0; i < size; i++)
			a[i] = rand.nextInt(20);
		a[size - 1] = -100;
		System.out.println(Arrays.toString(a));
		fun(a);
	}

}
